/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package opk.Solver;

import java.awt.Point;
import opk.Generator.Shape;

/**
 *
 * @author Dawid
 */
public class MinDistanceComparator implements java.util.Comparator {

    private Shape currentShape; //TODO czy nie zamienic na liczenie odl wczesniej potem sort

    public MinDistanceComparator(Shape currentShape)
    {
        currentShape.countAndSetGeometricCenter();
        this.currentShape = currentShape;
    }

    public int compare(Object shape1, Object shape2)
    {
        return distance((Shape) shape2) - distance((Shape) shape1);         // 1 - 2 max, 2 - 1 min
    }

    private int distance(Shape shape)
    {
        Point point1 = currentShape.getGeometricCenter();
        Point point2 = shape.getGeometricCenter();
        return (int)Math.sqrt(Math.pow((int)point1.x - (int)point2.x, 2) + Math.pow((int)point1.y - (int)point2.y, 2));
    }
}